﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace SeriesUtil.HelperClasses
{
    public class WebConnect
    {
        private String uri;
        private Int16 timeout;
        private Boolean isReachable;
        private String method;

        public WebConnect(String uri)
        {
            this.uri = uri;
            //this.timeout = 10000;   // 10 seconds to timeout per default
            this.method = "GET";    // default is GET
            this.isReachable = UriCheck();
        }

        private Boolean UriCheck()
        {
            HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;
            HttpWebResponse response;
            //request.Timeout = timeout;
            request.Method = method;
            try
            {
                response = request.GetResponse() as HttpWebResponse;
            }
            catch (Exception e)
            {
                throw e;
            }
            return response.StatusCode == HttpStatusCode.Found;
        }

        public Boolean IsReachable
        {
            get { return isReachable; }
        }

    }
}
